package com.google.multiplayer.snake.core.ui.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JLabel;
import javax.swing.JPanel;

import com.google.multiplayer.snake.core.ui.controller.MenuController;
import com.google.multiplayer.snake.core.ui.model.MenuModel;

public class MenuPanel extends JPanel implements MouseListener,
							MouseMotionListener{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private MenuModel myModel;
	private MenuController controller;
	JPanel panel1 = new JPanel();
	JPanel panel2 = new JPanel();
	JPanel panel3 = new JPanel();
	JPanel panel4 = new JPanel();
	JPanel panel5 = new JPanel();
	JPanel panel6 = new JPanel();
	JPanel panel7 = new JPanel();
	JPanel panel8 = new JPanel();

	JLabel label1;
	JLabel label2;
	JLabel label3;
	JLabel label4;
	JLabel label5;
	JLabel label6;
	
	/**
	 * Menu Panel, zu dem immer wieder nach einem Spiel gewechselt werden soll
	 * @param model
	 */
	
	public MenuPanel(MenuModel model){
		super();
		this.myModel = model;
		this.setBackground(new Color(0, 0, 30));
		setLayout(new BorderLayout());
		

		// panels
		panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 60));
		panel1.setBackground(new Color(0, 0, 30));
		panel1.setOpaque(false);

		panel2.setLayout(new GridLayout(5, 1));
		panel2.setBackground(new Color(0, 0, 30));

		panel3.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
		panel3.setBackground(new Color(0, 0, 30));

		panel4.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
		panel4.setBackground(new Color(0, 0, 30));

		panel5.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
		panel5.setBackground(new Color(0, 0, 30));

		panel6.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
		panel6.setBackground(new Color(0, 0, 30));

		panel7.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
		panel7.setBackground(new Color(0, 0, 30));

		// labels
		label1 = new JLabel("SNAKE");
		label1.setForeground(Color.GREEN);
		label1.setFont(new Font("Good Times", Font.BOLD, 50));

		label2 = new JLabel("Singleplayer");
		label2.setForeground(Color.yellow);
		label2.setFont(new Font("Good Times", Font.BOLD, 20));

		label3 = new JLabel("Multiplayer");
		label3.setForeground(Color.yellow);
		label3.setFont(new Font("Good Times", Font.BOLD, 20));

		label4 = new JLabel("Optionen");
		label4.setForeground(Color.yellow);
		label4.setFont(new Font("Good Times", Font.BOLD, 20));

		label5 = new JLabel("Credits");
		label5.setForeground(Color.yellow);
		label5.setFont(new Font("Good Times", Font.BOLD, 20));

		label6 = new JLabel("Exit");
		label6.setForeground(Color.yellow);
		label6.setFont(new Font("Good Times", Font.BOLD, 20));

		
		
		
		panel1.add(label1, BorderLayout.NORTH);
		panel3.add(label2);
		panel4.add(label3);
		panel5.add(label4);
		panel6.add(label5);
		panel7.add(label6);

		panel2.add(panel3);
		panel2.add(panel4);
		panel2.add(panel5);
		panel2.add(panel6);
		panel2.add(panel7);
		add(panel1, BorderLayout.NORTH);
		add(panel2, BorderLayout.CENTER);

		// Listeners
		panel1.addMouseListener(this);
		panel2.addMouseListener(this);
		panel3.addMouseListener(this);
		panel4.addMouseListener(this);
		panel5.addMouseListener(this);
		panel6.addMouseListener(this);
		panel7.addMouseListener(this);
		panel1.addMouseMotionListener(this);
		panel2.addMouseMotionListener(this);
		panel3.addMouseMotionListener(this);
		panel4.addMouseMotionListener(this);
		panel5.addMouseMotionListener(this);
		panel6.addMouseMotionListener(this);
		panel7.addMouseMotionListener(this);
		this.addMouseMotionListener(this);
	}
	
	@Override
	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseMoved(MouseEvent e) {
		if (e.getSource() == panel1) {
			panel1.setBackground(new Color(0, 0, 50));
			validate();
		} else {
			panel1.setBackground(new Color(0, 0, 30));
			validate();
		}
		if (e.getSource() == panel2) {
			panel2.setBackground(new Color(0, 0, 50));
			validate();
		} else {
			panel2.setBackground(new Color(0, 0, 30));
			validate();
		}
		if (e.getSource() == panel3) {
			panel3.setBackground(new Color(0, 0, 50));
			validate();
		} else {
			panel3.setBackground(new Color(0, 0, 30));
			validate();
		}
		if (e.getSource() == panel4) {
			panel4.setBackground(new Color(0, 0, 50));
			validate();
		} else {
			panel4.setBackground(new Color(0, 0, 30));
			validate();
		}

		if (e.getSource() == panel5) {
			panel5.setBackground(new Color(0, 0, 50));
			validate();
		} else {
			panel5.setBackground(new Color(0, 0, 30));
			validate();
		}
		if (e.getSource() == panel6) {
			panel6.setBackground(new Color(0, 0, 50));
			validate();
		} else {
			panel6.setBackground(new Color(0, 0, 30));
			validate();
		}

		if (e.getSource() == panel7) {
			panel7.setBackground(new Color(0, 0, 50));
			validate();
		} else {
			panel7.setBackground(new Color(0, 0, 30));
			validate();
		}

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		if (e.getSource() == panel7) {
			System.exit(0);
		}
		if( e.getSource() == panel3){
			controller.singlePlayerPushed();
		}
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}
	
	public void setController(MenuController controller){
		this.controller = controller;
	}
	
	public MenuController getController(){
		return this.controller;
	}
	
}
